package com.jz.community.moduleshoppingguide.neighbor.ui.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.ScrollView;

import com.jz.community.basecomm.utils.CommUtils;
import com.jz.community.moduleshoppingguide.R;

public class DialogInput extends Dialog {

    private Context context;
    ScrollView scrollView;
    RelativeLayout llCommentInput;
    EditText circleEt;
    RelativeLayout comment;

    public DialogInput(@NonNull Context context) {
        super(context, android.R.style.Theme_Translucent_NoTitleBar);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View view = LayoutInflater.from(context).inflate(R.layout.module_shoppingguide_layout_editview, null);
        setContentView(view);
        scrollView = findViewById(R.id.scrollView);
        llCommentInput = findViewById(R.id.rl_comment_input);
        circleEt = findViewById(R.id.circleEt);
        comment = findViewById(R.id.comment_editText_layout);
        scrollView.setOnTouchListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                dismiss();
            }
            return true;
        });
        setOnDismissListener(dialog -> hideKeyboard(circleEt));
    }

    private void hideKeyboard(EditText editText) {
        CommUtils.hideKeyboard(editText, (Activity) context);
    }

    public RelativeLayout getInputView() {
        return llCommentInput;
    }

    public String getEditString() {
        return circleEt.getText().toString();
    }

    public RelativeLayout getCommentBtn() {
        return comment;
    }
}
